package com.eclink.asset.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.eclink.asset.domain.dao.PrintTagModel;
import com.eclink.asset.mapper.PrintTagModelMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PrintTagModelService {

    @Resource
    private PrintTagModelMapper printTagModelMapper;

    /**
     * 查询列表
     *
     * @return 结果
     */
    public List<PrintTagModel> selectList(Integer labelType) {
        QueryWrapper<PrintTagModel> qw = new QueryWrapper<>();
        qw.eq("label_type", labelType);
        return printTagModelMapper.selectList(qw);
    }

    /**
     * 新增
     *
     * @param entity 对象
     * @return 结果
     */
    public int insert(PrintTagModel entity) {
        return printTagModelMapper.insert(entity);
    }

    /**
     * 修改
     *
     * @param entity 对象
     * @return 结果
     */
    public int update(PrintTagModel entity) {
        return printTagModelMapper.updateById(entity);
    }

    public void deleteById(Long id) {
        printTagModelMapper.deleteById(id);
    }

    public void setSelected(Long id) {

        printTagModelMapper.unselectAll();
        PrintTagModel one = printTagModelMapper.selectById(id);
        one.setSelected(true);
        printTagModelMapper.updateById(one);
    }

    public PrintTagModel getSelected() {

        QueryWrapper<PrintTagModel> qw = new QueryWrapper<>();
        qw.eq("selected", 1);
        List<PrintTagModel> res = printTagModelMapper.selectList(qw);
        if (res == null || res.isEmpty()) {
            return null;
        }
        return res.get(0);
    }


}
